<?php


namespace app\voip\controller;


use AlibabaCloud\EcsInc\V20160314\CancelAgreement;
use app\voip\func\AgeGroupFunc;
use app\voip\func\AirlinesLogFunc;
use app\voip\func\CallTaskFunc;
use app\voip\func\ChildrenFunc;
use app\voip\func\CompanyFunc;
use app\voip\func\ConsumptionLevelFunc;
use app\voip\func\CulturalFunc;
use app\voip\func\ExcelAuthFunc;
use app\voip\func\ExcelListFunc;
use app\voip\func\HomeAddressFunc;
use app\voip\func\HomeTypeFunc;
use app\voip\func\JobTypeFunc;
use app\voip\func\PatriarchFunc;
use app\voip\func\ProvinceFunc;
use app\voip\func\SmsFunc;
use app\voip\func\UserSigFunc;
use app\voip\func\WorksheetFunc;
use app\voip\model\Sms;
use phpDocumentor\Reflection\Types\Array_;
use think\Db;
use vae\controller\AdminCheckAuth;

class AirlinesController extends AdminCheckAuth
{

    /**
     * 任务呼叫中心
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function excelCall()
    {


        session('callType',input('type',1));


        $uid=vae_get_login_admin('id');
        $tid=input('id');

        $where=[];
        $where['c2.is_close']=1;
        $where['c2.type']=1;

        $where['c1.uid']=$uid;
        $where['c1.tid']=$tid;
        $taskInfo=CallTaskFunc::findUserTaskInfo($where);
        $excelWhere=[];
        $excelWhere['number']=array('in',$taskInfo['enumber']);
        $excelList=ExcelListFunc::userExcelList($excelWhere);
        $provinces=$this->provinces(0);
        $smsWhere=[];
        $smsWhere['id']=array('in',$taskInfo['sms']);
        $smsInfo=SmsFunc::getSmsInfoList($smsWhere);

        session('taskId',$tid);
        return view('',['excelList'=>$excelList,'provinces'=>$provinces,'smsInfo'=>json_encode($smsInfo)]);
    }

    /**
     * 区域呼叫
     * @return \Swoft\Http\Message\Server\Response|\think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function areaCall()
    {
        $uid=vae_get_login_admin('id');
        $where=[];
        $where['uid']=$uid;
        $where['status']=1;
        $result=ExcelAuthFunc::userFindGid($where);
        $gid=[];
        foreach ($result as $val)
        {
            $gid[]=$val->gid;
        }
        $gidStr=implode(',',$gid);
        $auth=[];
        $auth['id']=array('in',$gidStr);
        $auth['type']=2;
        $result=ExcelAuthFunc::userFindAuthEid($auth);
        $eid=[];
        foreach ($result as $val)
        {
            $eid[]=$val->eid;
        }
        $eidStr=implode(',',$eid);
        $excel=[];
        $excel['id']=array('in',$eidStr);


        session('airlinesAreaId',explode(',',$eidStr));

        $provinces=$this->provinces(0);

        return view('',['provinces'=>$provinces]);
    }


    /**
     * @param $page
     * @param $limit
     * @param $keywords
     * @return string|void
     * @throws \think\exception\DbException
     * @throws \think\Exception
     */
    public function airlinesExcelInfo($page, $limit, $keywords='')
    {
            try{
                $keywords['page']=$page;
                $keywords['limit']=$limit;
                $validate=validate('AirlinesAuth');
                if (!$validate->scene(__FUNCTION__)->check($keywords)){
                    throw new \Exception($validate->getError());
                }
                $excelId=$keywords['excelId'];

                $excelWhere=[];
                $excelWhere['id']=$excelId;
                $excelWhere['download_password']=md5($keywords['password']);

                $result=ExcelListFunc::find($excelWhere);
                if (!$result){
                    throw new \Exception('Excel 密码错误！');
                }
            }catch (\Exception $e){
                return vae_assign_table(0,'',['code'=>0,'msg'=>'', 'count'=>'','data'=>[]]);
            }
            /** @var TYPE_NAME $dataset  呼叫状态*/
            $dataset=$keywords['dataset'];

            /** @var TYPE_NAME $relation 关系过滤*/
            $relation=$keywords['relation'];

            $where = array();
            $param = vae_get_param();

            $rows = empty($param['limit']) ? \think\Config::get('paginate.list_rows') : $param['limit'];
            $province=$keywords['province'];
            $city=$keywords['city'];
            $county=$keywords['county'];
            $resultData='';
            $orderSet='asc';
            if ($keywords['order']==1){
                $orderSet='asc';
            }else{
                $orderSet='desc';
            }
            switch ($relation){
                case 1:
                    $where['p1.eid']=$excelId;
                    $where['c2.eid']=$excelId;
                    $where=$this->wheProvinces($province,$city,$county,$where,1);
                    $where=$this->dataset($dataset,$where,1);
                    $order='p1.id '.$orderSet;
                    $resultData=$this->getExcelRelationInfo($where,$rows,$param,$order);
                    break;
                case 2:
                    $where['p1.eid']=$excelId;
                    $order='p1.id '.$orderSet;
                    $where=$this->wheProvinces($province,$city,$county,$where,2);
                    $where=$this->dataset($dataset,$where,2);
                    $resultData=$this->getExcelRelationpInfo($where,$rows,$param,$order);
                    break;
                case 3:
                    $where['c2.eid']=$excelId;
                    $order='c2.id '.$orderSet;
                    $where=$this->wheProvinces($province,$city,$county,$where,3);
                    $where=$this->dataset($dataset,$where,3);
                    $resultData=$this->getExcelRelationcInfo($where,$rows,$param,$order);
                    break;
            }
            $resultData=$resultData->toArray();
            $pcData=$resultData['data'];

            foreach ($pcData as $key=>$val){
                $result1=$result2=$result3=[];
                if (!empty($val['cid'])){
                    $uwhere=[];
                    $uwhere['uid']=$val['cid'];
                    $uwhere['type']=2;
                    $result1=AirlinesLogFunc::findLog($uwhere);
                    if ($result1){
                        $result1=$result1->toArray();
                    }

                }
                if (!empty($val['pid'])){
                    $pwhere=[];
                    $pwhere['uid']=$val['pid'];
                    $pwhere['type']=1;
                    $result2=AirlinesLogFunc::findLog($pwhere);
                    if ($result2){
                        $result2=$result2->toArray();
                    }
                }

                switch ($relation){
                    case 1:
                        if (!empty($result1) && !empty($result2)){
                            if ($result2['create_time']>$result1['create_time']){
//                                $result3['userObj']='家长';
                                $result3['userObj']=$result2['username'];
                                $result3['userObjStatus']=$result2['call_status'];
                                $result3['userObjMark']=$result2['mark'];
                                $result3['create_time']=$result2['create_time'];

                            }else{
//                                $result3['userObj']='娃娃';
                                $result3['userObj']=$result1['username'];
                                $result3['userObjStatus']=$result1['call_status'];
                                $result3['userObjMark']=$result1['mark'];
                                $result3['create_time']=$result1['create_time'];

                            }
                        }elseif(!empty($result2)){
//                            $result3['userObj']='家长';
                            $result3['userObj']=$result2['username'];
                            $result3['userObjStatus']=$result2['call_status'];
                            $result3['userObjMark']=$result2['mark'];
                            $result3['create_time']=$result2['create_time'];
                        }elseif(!empty($result1)){
//                            $result3['userObj']='娃娃';
                            $result3['userObj']=$result1['username'];
                            $result3['userObjStatus']=$result1['call_status'];
                            $result3['userObjMark']=$result1['mark'];
                            $result3['create_time']=$result1['create_time'];
                        }
                        break;
                    case 2:
                        if (!empty($result2)){
//                            $result3['userObj']='家长';
                            $result3['userObj']=$result2['username'];
                            $result3['userObjStatus']=$result2['call_status'];
                            $result3['userObjMark']=$result2['mark'];
                            $result3['create_time']=$result2['create_time'];
                        }
                        break;
                    case 3:
                        if (!empty($result1)){
//                            $result3['userObj']='娃娃';
                            $result3['userObj']=$result1['username'];
                            $result3['userObjStatus']=$result1['call_status'];
                            $result3['userObjMark']=$result1['mark'];
                            $result3['create_time']=$result1['create_time'];

                        }
                        break;
                }


                $pcData[$key]['userObj']=$result3['userObj'] ?? '尚未拨号';
                $pcData[$key]['userObjStatus']=$result3['userObjStatus'] ?? '尚未拨号';
                $pcData[$key]['userObjMark']=$result3['userObjMark'] ?? '尚未拨号';
                $pcData[$key]['create_time']=$result3['create_time'] ?? '尚未拨号';

            }
            $resultData['data']=$pcData;
            return vae_assign_table(0,'',$resultData);
    }

    public function airlinesAreaInfo($page, $limit, $keywords='')
    {
        try{
            $keywords['page']=$page;
            $keywords['limit']=$limit;
            $validate=validate('AirlinesAuth');
            if (!$validate->scene(__FUNCTION__)->check($keywords)){
                throw new \Exception($validate->getError());
            }
            $province=$keywords['province'];
            $city=$keywords['city'];
            $county=$keywords['county'];
            if (empty($province)){
                throw new \Exception('数据错误！');
            }
            $areaquth=true;
            $airlinesAreaId=session('airlinesAreaId');
            if (in_array($province,$airlinesAreaId)){
                $areaquth=false;
            }elseif( in_array($city,$airlinesAreaId) ){
                $areaquth=false;
            }elseif (in_array($county,$airlinesAreaId)){
                $areaquth=false;
            }
            if ($areaquth){
                throw new \Exception('没有权限！');
            }

        }catch (\Exception $e){

            return vae_assign_table(0,'',['code'=>0,'msg'=>'', 'count'=>'','data'=>[]]);
        }
        /** @var TYPE_NAME $dataset  呼叫状态*/
        $dataset=$keywords['dataset'];

        /** @var TYPE_NAME $relation 关系过滤*/
        $relation=$keywords['relation'];

        $where = array();
        $param = vae_get_param();

        $rows = empty($param['limit']) ? \think\Config::get('paginate.list_rows') : $param['limit'];
        $province=$keywords['province'];
        $city=$keywords['city'];
        $county=$keywords['county'];
        $resultData='';
        $orderSet='asc';
        if ($keywords['order']==1){
            $orderSet='asc';
        }else{
            $orderSet='desc';
        }
        switch ($relation){
            case 1:
                $where=$this->wheProvinces($province,$city,$county,$where,1);
                $where=$this->dataset($dataset,$where,1);
                $order='p1.id '.$orderSet;
                $resultData=$this->getExcelRelationInfo($where,$rows,$param,$order);
                break;
            case 2:
                $order='p1.id '.$orderSet;
                $where=$this->wheProvinces($province,$city,$county,$where,2);
                $where=$this->dataset($dataset,$where,2);
                $resultData=$this->getExcelRelationpInfo($where,$rows,$param,$order);
                break;
            case 3:
                $order='c2.id '.$orderSet;
                $where=$this->wheProvinces($province,$city,$county,$where,3);
                $where=$this->dataset($dataset,$where,3);
                $resultData=$this->getExcelRelationcInfo($where,$rows,$param,$order);
                break;
        }
        $resultData=$resultData->toArray();
        $pcData=$resultData['data'];

        foreach ($pcData as $key=>$val){
            $result1=$result2=$result3=[];
            if (!empty($val['cid'])){
                $uwhere=[];
                $uwhere['uid']=$val['cid'];
                $uwhere['type']=2;
                $result1=AirlinesLogFunc::findLog($uwhere);
                if ($result1){
                    $result1=$result1->toArray();
                }

            }
            if (!empty($val['pid'])){
                $pwhere=[];
                $pwhere['uid']=$val['pid'];
                $pwhere['type']=1;
                $result2=AirlinesLogFunc::findLog($pwhere);
                if ($result2){
                    $result2=$result2->toArray();
                }
            }

            switch ($relation){
                case 1:
                    if (!empty($result1) && !empty($result2)){
                        if ($result2['create_time']>$result1['create_time']){
//                            $result3['userObj']='家长';
                            $result3['userObj']=$result2['username'];
                            $result3['userObjStatus']=$result2['call_status'];
                            $result3['userObjMark']=$result2['mark'];
                            $result3['create_time']=$result2['create_time'];

                        }else{
//                            $result3['userObj']='娃娃';
                            $result3['userObj']=$result1['username'];

                            $result3['userObjStatus']=$result1['call_status'];
                            $result3['userObjMark']=$result1['mark'];
                            $result3['create_time']=$result1['create_time'];

                        }
                    }elseif(!empty($result2)){
//                        $result3['userObj']='家长';
                        $result3['userObj']=$result2['username'];

                        $result3['userObjStatus']=$result2['call_status'];
                        $result3['userObjMark']=$result2['mark'];
                        $result3['create_time']=$result2['create_time'];
                    }elseif(!empty($result1)){
//                        $result3['userObj']='娃娃';
                        $result3['userObj']=$result3['username'];

                        $result3['userObjStatus']=$result1['call_status'];
                        $result3['userObjMark']=$result1['mark'];
                        $result3['create_time']=$result1['create_time'];
                    }
                    break;
                case 2:
                    if (!empty($result2)){
//                        $result3['userObj']='家长';
                        $result3['userObj']=$result2['username'];

                        $result3['userObjStatus']=$result2['call_status'];
                        $result3['userObjMark']=$result2['mark'];
                        $result3['create_time']=$result2['create_time'];
                    }
                    break;
                case 3:
                    if (!empty($result1)){
//                        $result3['userObj']='娃娃';
                        $result3['userObjStatus']=$result1['call_status'];
                        $result3['userObjMark']=$result1['mark'];
                        $result3['create_time']=$result1['create_time'];
                        $result3['userObj']=$result1['username'];

                    }
                    break;
            }


            $pcData[$key]['userObj']=$result3['userObj'] ?? '尚未拨号';
            $pcData[$key]['userObjStatus']=$result3['userObjStatus'] ?? '尚未拨号';
            $pcData[$key]['userObjMark']=$result3['userObjMark'] ?? '尚未拨号';
            $pcData[$key]['create_time']=$result3['create_time'] ?? '尚未拨号';

        }
        $resultData['data']=$pcData;
        return vae_assign_table(0,'',$resultData);
    }


    private function dataset($dataset,$where,$type)
    {
        switch ($type){
            case 1:
                if ($dataset!==''){
                    $where['c2.call_status']=$dataset;
                    $where['p1.call_status']=$dataset;
                }

                break;
            case 2:
                if ($dataset!==''){
                    $where['p1.call_status']=$dataset;

                }
                break;
            case 3:
                if ($dataset!==''){
                    $where['c2.call_status']=$dataset;
                }
        }
        return $where;
    }


    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    private function getExcelRelationInfo($where, $rows, $param,$order)
    {
        return ExcelListFunc::getRelationAll($where, $rows, $param,$order);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @param $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    private function getExcelRelationpInfo($where, $rows, $param,$order)
    {
        return ExcelListFunc::getRelationpAll($where, $rows, $param,$order);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @param $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    private function getExcelRelationcInfo($where, $rows, $param,$order)
    {
        return ExcelListFunc::getRelationcAll($where, $rows, $param,$order);
    }
    private function wheProvinces($province,$city,$county,$where,$type)
    {
        if (!empty($province)){

            $where=$this->ptype('province',$province,$type,$where);
        }
        if (!empty($city)){
            $where=$this->ptype('city',$city,$type,$where);

        }
        if (!empty($county)){
            $where=$this->ptype('county',$county,$type,$where);
        }
        return $where;
    }

    /**
     * @param $key
     * @param $val
     * @param $type
     * @param $where
     * @return mixed
     */
    private function ptype($key, $val, $type, $where)
    {
        switch ($type){
            case 1:
                $where['h1.'.$key]=$val;
                $where['h2.'.$key]=$val;
                break;
            case 2:
                $where['h1.'.$key]=$val;
                break;
            case 3:
                $where['h2.'.$key]=$val;
                break;
        }
        return $where;
    }


    /**
     * ajax 获取家长信息并获取通话记录
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function ajaxGetPCInfoAndLog()
    {
        if(!request()->isAjax()){return false;}
        $id=input('id');
        $type=input('type');
        $hkey="pid";
        if ($type==1){
            $pinfo=PatriarchFunc::getInfo($id);

        }elseif($type==2){
            $hkey="cid";
            $pinfo=ChildrenFunc::getInfo($id);
        }
        $pinfo['ageName']='';
        if (!empty($pinfo['ageg'])){
            $pinfo['ageName']=AgeGroupFunc::find(['id'=>$pinfo['ageg']])['name'];
        }
        $logList=AirlinesLogFunc::getLogList($id,$type);
        $where=[];
        $where[$hkey]=$id;
        $addres=HomeAddressFunc::selectCount($where,3);
        foreach ($addres as $key=>$val){
            $addres[$key]['province']=ProvinceFunc::find(['id'=>$val['province'],'type'=>0])['toponymy'];
            $addres[$key]['city']=ProvinceFunc::find(['id'=>$val['city'],'type'=>1])['toponymy'];
            $addres[$key]['county']=ProvinceFunc::find(['id'=>$val['county'],'type'=>2])['toponymy'];
            $addres[$key]['ht_id']=HomeTypeFunc::find(['id'=>$val['ht_id']])['type_name'];
        }
        $where=[];
        $where['up_id']=$id;
        $worksheet=WorksheetFunc::selectCount($where,3);

        foreach ($worksheet as $key=>$val){
            $worksheet[$key]['company_id']=CompanyFunc::find(['id'=>$val['company_id']])['company_name'];
            $worksheet[$key]['job_id']=JobTypeFunc::find(['id'=>$val['job_id']])['type_name'];
            $worksheet[$key]['levelname']=ConsumptionLevelFunc::find(['id'=>$val['level_id']])['name'];
        }
        $where=[];
        $where['id']=array('in',$pinfo['sigs']);
        $sigs=UserSigFunc::selectUserSig($where);
        $culturalname=AirlinesLogFunc::getCultural($pinfo['cultural_id'])['name'] ?? ' ';
        $levelName=ConsumptionLevelFunc::find(['id'=>$pinfo['level_id']])['name'] ?? '';


        return [$pinfo,$logList,$sigs,$addres,$worksheet,$culturalname,$levelName];
    }
    /**
     * @return array|false|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function ajaxGetUserInfo()
    {
        $id=input('id');
        $type=input('type');
        $info='';
        if ($type==1){
            $info=PatriarchFunc::getInfo($id);

        }elseif($type==2){
            $info=ChildrenFunc::getInfo($id);
        }
        $where=[];
        $where['status']=1;
        $cultural=CulturalFunc::select($where);

        $consumption_level=ConsumptionLevelFunc::select();
        $ageGroup=AgeGroupFunc::select($where);

        $userSig=UserSigFunc::selectUserSig($where);
        session('callNumber',$info->getData('phone'));


        return ['status'=>1,'data'=>$info,'cultural'=>$cultural,'consumption_level'=>$consumption_level,'ageGroup'=>$ageGroup,'userSig'=>$userSig];
    }

    /**
     * 日志上传
     * @return array
     */
    public function uploadLog()
    {
        try{
            $validate=validate('AirlinesAuth');
            if (!$validate->scene(__FUNCTION__)->check(input()['data'])){
                throw new \Exception($validate->getError());
            }
            Db::startTrans();
            $data=input()['data'];
            $data['aid']=vae_get_login_admin('id');
            $data['tid']=session('taskId');
            $data['phone']=is_numeric($data['phone']) ? $data['phone']:session('callNumber');
            $data['age']=strtotime($data['age']);
            $this->addWorkSheet($data);
            $this->addHomeAddres($data);
            $ageGroup=$data['age_group'];//年龄段分组
            $cultural_id=$data['cultural_id'];//文化层次
            $age=$data['age'];
            $level_id=$data['level_id'];//消费水准
            $interest=$data['interest'];//兴趣
            $update=[];
            $update['interest']=$interest;
            $update['call_status']=1;
            $update['cultural_id']=$cultural_id;
            $update['sigs']=$data['sigs'];
            $update['level_id']=$level_id;
            $update['ageg']=$ageGroup;
            $update['age']=$age;
            AirlinesLogFunc::uploadLog($data);
            $res=$this->updateUserCallStatus($data['type'],$update,['id'=>$data['uid']]);
            Db::commit();
            return ['status'=>1,'msg'=>'保存成功！','create_time'=>date("Y-m-d H:i:s")];
        }catch (\Exception $e){
            Db::rollback();
            return ['status'=>0,'msg'=>$e->getMessage()];
        }
    }

    /**
     * @param $data
     * @throws \think\exception\DbException
     */
    private function addHomeAddres($data)
    {
        if (!empty($data['province']) && !empty($data['city']) && !empty($data['county']) && !empty($data['detailed_addr']) && !empty($data['ht_id']) ){

            $ht_id=HomeTypeFunc::checkSave([$data['ht_id']=>$data['ht_id']])[$data['ht_id']];
            $addData=[];

            $pdata=[];
            $pdata[$data['province']]=[$data['province']];
            $pdata[$data['province']][$data['city']]=[$data['city']];
            $pdata[$data['province']][$data['city']][$data['county']]=$data['county'];
            $pdata=ProvinceFunc::checkSave($pdata);
            $addData['province']=$pdata[$data['province']][0];
            $addData['city']=$pdata[$data['province']][$data['city']][0];
            $addData['county']=$pdata[$data['province']][$data['city']][$data['county']];
            $addData['detailed_addr']=$data['detailed_addr'];
            if ($data['type']==1){
                $addData['pid']=$data['uid'];
            }else{
                $addData['cid']=$data['uid'];
            }
            $addData['ht_id']=$ht_id;
            $addData['type']=$data['type'];
            $addData['remark']=$data['hremark'] ?? '日志';


            HomeAddressFunc::add($addData);
        }
        return;
    }

    /**
     * @param $data
     * @throws \think\exception\DbException
     */
    private function addWorkSheet($data)
    {
        if (!empty($data['company']) && !empty($data['job']) && !empty($data['ymoney']) &&  !empty($data['disburse']) && !empty($data['wlevel_id'])){
            $addData=[];
            $addData['company_id']=CompanyFunc::checkSave([$data['company']=>$data['company']])[$data['company']];
            $addData['job_id']=JobTypeFunc::checkSave([$data['job']=>$data['job']])[$data['job']];
            $addData['intro']=$data['wintro'];
            $addData['ymoney']=$data['ymoney'];
            $addData['level_id']=$data['wlevel_id'];
            $addData['disburse']=$data['disburse'];
            $addData['remark']=$data['wremark'];
            $addData['up_id']=$data['uid'];
            WorksheetFunc::add($addData);
        }
        return;
    }

    /**
     * @param $type
     * @param $update
     * @param $where
     * @return \app\voip\model\EChildren|\app\voip\model\EPatriarch|string
     */
    private function updateUserCallStatus($type, $update, $where)
    {
        $result='';
        switch ($type)
        {
            case 1:
                $result=PatriarchFunc::update($update,$where);
                break;
            case 2:
                $result=ChildrenFunc::update($update,$where);
                break;
        }
        return $result;
    }
    /**
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function ajaxCallLog()
    {
        $id=input('id');
        $type=input('type');
        $where=[];
        $where['id']=(int)$id;
        $where['type']=(int)$type;
        $info=AirlinesLogFunc::findLog($where);
        session('callNumber',$info->getData('phone'));
        $where=[];
        $where['status']=1;
        $cultural=CulturalFunc::select($where);
        switch ((int)$type){
            case 1:
                $where=[];
                $where['status']=1;
                $consumption_level=ConsumptionLevelFunc::select();
                $ageGroup=AgeGroupFunc::select($where);
                $userSig=UserSigFunc::selectUserSig($where);
                $infoResult=PatriarchFunc::getInfo($info['uid']);
                $info['sigs']=$infoResult['sigs'];
                $info['cultural_id']=$infoResult['cultural_id'];
                $info['level_id']=$infoResult['level_id'];
                $info['ageg']=$infoResult['ageg'];
                $info['interest']=$infoResult['interest'];
                break;
        }
        return ['status'=>1,'data'=>$info,'cultural'=>$cultural,'consumption_level'=>$consumption_level,'ageGroup'=>$ageGroup,'userSig'=>$userSig];
    }
    /**
     * @param $type
     * @param string $topid
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function provinces($type, $topid='')
    {
        $where=[];
        if (!empty($topid)){
            $where['top_id']=$topid;
        }
        $where['type']=$type;
        return ProvinceFunc::getInfo($where);
    }
}